//
//  SSStatusFooterView.swift
//  MyMicroBlog
//
//  Created by stevenSu on 15/8/1.
//  Copyright © 2015年 stevenSu. All rights reserved.
//

import UIKit
private let sepViewRatio: CGFloat = 0.7
private let footerViewBackgroundColor = UIColor(white: 0.95, alpha: 1.0)
private let buttonTopInset: CGFloat = 1.0
let SSStatusFooterViewRetweetButtonNotification = "SSStatusFooterViewRetweetButtonNotification"
let SSStatusFooterViewStatus = "SSStatusFooterViewStatus"

class SSStatusFooterView: UIView {
    private lazy var retweetButton: UIButton = {
        let btn = UIButton(imgName: "timeline_icon_retweet", title: " 转发")
        btn.addTarget(self, action: "shareRetweet", forControlEvents: UIControlEvents.TouchUpInside)
        return btn
    }()
    private lazy var commentButton: UIButton = UIButton(imgName: "timeline_icon_comment", title: " 评论")
    private lazy var likeButton: UIButton = UIButton(imgName: "timeline_icon_unlike", title: " 赞")
    private lazy var sepViewLeft: UIImageView = {
        let view = UIImageView(image: UIImage(named: "timeline_card_bottom_line_highlighted"))
        view.alpha = sepViewRatio
        return view
    }()
    private lazy var sepViewRight: UIImageView = {
        let view = UIImageView(image: UIImage(named: "timeline_card_bottom_line_highlighted"))
        view.alpha = sepViewRatio
        return view
        }()
    var status: SSStatus?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
        backgroundColor = footerViewBackgroundColor
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func shareRetweet() {
        let dict = [SSStatusFooterViewStatus: status!]
        NSNotificationCenter.defaultCenter().postNotificationName(SSStatusFooterViewRetweetButtonNotification, object: self, userInfo: dict)
    }
    
    private func setupUI() {
        addSubview(retweetButton)
        addSubview(commentButton)
        addSubview(likeButton)
        addSubview(sepViewLeft)
        addSubview(sepViewRight)
        
        ff_HorizontalTile([retweetButton, commentButton, likeButton], insets: UIEdgeInsets(top: buttonTopInset, left: 0, bottom: 0, right: 0))
        sepViewLeft.ff_AlignInner(type: ff_AlignType.CenterRight, referView: retweetButton, size: CGSize(width: sepViewLeft.bounds.width, height: sepViewLeft.bounds.height * sepViewRatio))
        sepViewRight.ff_AlignInner(type: ff_AlignType.CenterRight, referView: commentButton, size: CGSize(width: sepViewLeft.bounds.width, height: sepViewLeft.bounds.height * sepViewRatio))
    }
}
